/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						script_increase_experience.cpp

	$Header: /heroes4/script_increase_experience.cpp $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )

#include "adventure_map.h"
#include "adventure_map_window.h"
#include "basic_dialog.h"
#include "script_increase_experience.h"
#include "script_targeting.h"

namespace {
	static t_hero*	g_target_hero = NULL;
	static int		g_adjusted_amount = 0;
}

void t_script_increase_experience::execute(t_script_context_army const& context) const
{
	// A placed event might yield a "gained a level" dialog.  Stop the army
	// just in case.
	context.map->get_map_window()->halt_movement();
	
	t_script_hero_adjustment_action< t_uint32 >::execute(context);
}

void t_script_increase_experience::make_adjustment(t_adventure_map* map, t_hero* hero) const
{
	if ( (g_target_hero = hero) == NULL) return;
	hero->add_experience(get_adjustment(), map);
	hero->check_level( *map, map->get_map_window(), NULL);
}

void t_script_increase_experience::add_icons(t_basic_dialog* dialog) const
{
	if (g_target_hero == NULL) return;
	dialog->add_experience(get_adjustment(), g_target_hero);
	g_target_hero = NULL;
}

void t_script_increase_experience_level::make_adjustment(t_adventure_map* map, t_hero* hero) const
{
	if ( (g_target_hero = hero) == NULL) return;
	g_adjusted_amount = hero->get_experience(hero->get_level() + get_adjustment()) - hero->get_experience();
	hero->add_experience(g_adjusted_amount, map);
	hero->check_level( *map, map->get_map_window(), NULL);
}

void t_script_increase_experience_level::add_icons(t_basic_dialog* dialog) const 
{
	if (g_target_hero == NULL) return;
	dialog->add_experience(g_adjusted_amount, g_target_hero);
	g_target_hero = NULL;
}

void t_script_increase_experience_level::execute(t_script_context_army const& context) const
{
	context.map->get_map_window()->halt_movement();

	t_script_hero_adjustment_action< t_uint8 >::execute(context);
}
